from pathlib import Path
import os

cwd = Path.cwd()
os.chdir(cwd)

# 找到.c 和.h 文件
file_list = cwd.glob('*.[ch]')
file_name_list = [t.name for t in file_list]
text = '\n'.join(file_name_list)

list_file = Path('source-files.txt')

with open(list_file, 'w', encoding='utf-8') as f:
    f.write(text)

print('== SOURCE FILE LIST ==')
print(text)

os.system(f'clang-format -i -files="{list_file.name}"')

print('== FORMATED ==')
os.system('pause')
os.remove(list_file)
